package com.sunnada.demo.log.mongodb;

import com.mongodb.DBObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.spi.LoggingEvent;
import org.log4mongo.LoggingEventBsonifier;
import org.log4mongo.MongoDbAppender;

/**
 * @program: mybatisproject2
 * @description:
 * @author: 李瑞益
 * @create: 2018-10-28 14:26
 **/
public class ConciseMongoDbAppender extends MongoDbAppender {

    private LoggingEventBsonifier bsonifier = new ConciseLoggingEventBsonifier();

    @Override
    protected void append(LoggingEvent loggingEvent) {
        if (StringUtils.isNotBlank(loggingEvent.getLoggerName())
                && loggingEvent.getLoggerName().contains("com.sunnada")) {
            DBObject bson = this.bsonifier.bsonify(loggingEvent);
            this.append(bson);
        }
    }
}